package com.dylan.历史.java8.新日期;

import com.dylan.历史.util.SleepUtils;

import java.time.Duration;
import java.time.Instant;

/**
 * Created by Dylan on 2018/7/27.
 */
public class 瞬时 {

    public static void main(String[] args) {
        Duration timeElapsed = compute(() -> SleepUtils.milliseconds(232));
        Duration timeElapsed2 = compute(() -> SleepUtils.milliseconds(732));
        boolean b = timeElapsed.multipliedBy(2).minus(timeElapsed2).isNegative();
        System.out.println(timeElapsed.toMillis() + " 比 " + timeElapsed2.toMillis() + " 快两倍:" + b);

        Instant instant1 = Instant.EPOCH;
        System.out.println(instant1.toString());

        Instant instant2 = Instant.parse("2016-02-29T10:15:30Z");
//        Instant instant2 = Instant.parse("2017-02-29T10:15:30Z"); // 非闰年,无法解析
        System.out.println(instant2.toString());

        Instant instant3 = instant2.plusSeconds(10000000);
        System.out.println(instant3.toString());


    }

    static Duration compute(Runnable runnable) {
        Instant start  = Instant.now();
        runnable.run();
        Instant end  = Instant.now();
        return Duration.between(start, end);
    }
}
